From 7ef51da1c1650586a51a650042815dab97e3be3f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 13 May 2020 19:43:04 -0400 Subject: [PATCH] listbox: Don't steal focus-on-click If a row has content that is focus-on-click, and is set to focus-on-click itself, then the row steals the focus fromt he content, since it uses focus-on-click on button release, as opposed to button press. Avoid that by refusing to take focus if it is already on some descendent of the row. This was showing up in the widget-factory listbox on page 2, where clicking on the spinbutton would briefly put the focus on the spinbutton, only to lose it to the row. --- gtk/gtklistbox.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index 8e2c5409ea..bc4676566f 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -1516,7 +1516,13 @@ gtk_list_box_update_cursor (GtkListBox *box, box->cursor_row = row; ensure_row_visible (box, row); if (grab_focus) - gtk_widget_grab_focus (GTK_WIDGET (row)); + { + GtkWidget *focus; + + focus = gtk_root_get_focus (gtk_widget_get_root (GTK_WIDGET (box))); + if (!focus || !gtk_widget_is_ancestor (focus, GTK_WIDGET (row))) + gtk_widget_grab_focus (GTK_WIDGET (row)); + } gtk_widget_queue_draw (GTK_WIDGET (row)); _gtk_list_box_accessible_update_cursor (box, row); } -- 2.30.2